// pages/order/detail.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    paddingTop: app.globalData.model.topMargin,
    navHeight: app.globalData.model.topHeight,
    bottomHeight: app.globalData.model.bottomHeight,
    scrollTop: 0,

    order_status: 1,
    isShEnd: 0,

    address: {
      name: '李培哲',
      phone: '182*****360',
      address: '湖北省 武汉市 武昌区 光谷华中科技大学南一宿 舍楼 606室 '
    },
    goodData: {
      no: '',
      good_img: '/images/home_img2.png',
      good_name: '云南七彩菌汤包干货煲汤山珍菌',
      good_type: '菌种一',
      good_price: '80',
      good_num: 1,
      good_integral: 50,
    },
    good_no: '2024032811078956',
    order_time: '2024-07-13 20:37:20',
    pay_status: '微信支付',
    order_price: '40.00',
    pay_time: '2024-03-28 11:09:15',//支付时间
    endClock: '2024-07-13 21:37:20', // 结束时间倒计时对象
    endDate: '',
    isEnd: false,

    isMask: false,
    isCancelOrder: false,
    isShOrder: false
  },
  copyNo(){
    var no = this.data.good_no;
    wx.setClipboardData({
      data: no,
      success: function(res){
        wx.showToast({
          title: '复制成功',
        })
      }
    })
  },
  // 结束时间倒计时
  endTimeClock() {
    let that = this;
    clearInterval(that.data.count_down);
    that.data.count_down = setInterval(() => {
      let currTime = new Date().getTime();
      let endTime = new Date(that.data.endClock).getTime();
      let lag = endTime - currTime;
      if (lag > 0) { // 还没结束
        let seconds = Math.abs(lag) / 1000;
        let hours = Math.floor(seconds / 3600);
        let minite = Math.floor((seconds % 3600) / 60);
        let second = Math.floor(seconds % 60);

        that.setData({
          endDate: minite + '分' + second + '秒',
        })
      } else {
        // 倒计时结束，刷新数据
        clearInterval(that.data.count_down);
        that.setData({
          isEnd: true
        })
      }
    }, 1000)
  },
  //取消订单
  openCancelOrder(){
    this.setData({
      isMask: true,
      isCancelOrder: true
    })
  },
  closeMask(){
    this.setData({
      isMask: false,
      isCancelOrder: false,
      isShOrder: false
    })
  },
  openShOrder(){
    this.setData({
      isMask: true,
      isShOrder: true
    })
  },
  goPath(e){
    wx.navigateTo({
      url: e.currentTarget.dataset.url,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.endTimeClock();
  },
  onPageScroll(e) {
    this.setData({
      scrollTop: e.scrollTop
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})